package org.hpin.asset.dao;

import java.util.List;

import org.hpin.asset.entity.Distributed;
import org.hpin.common.core.orm.BaseDao;
import org.springframework.stereotype.Repository;
@Repository()
public class DistributedDao extends BaseDao{
	public List findDistributedByAttribute(Class clazz,String attribute,String value){
		String queryString="from "+clazz.getSimpleName();
		if(attribute!=""&&attribute!=null){
			queryString+=" where "+attribute+"=\'"+value+"\'";
		}
		System.out.println("queryString:"+queryString);
		return super.getHibernateTemplate().find(queryString);
	}
	public void updateDistributed(Distributed distributed,String id){
		List<Distributed> list= (List<Distributed>) this.findDistributedByAttribute(Distributed.class, "assetId", id);
		if(list.size()!=0){
			for(Distributed dis:list){
				super.getHibernateTemplate().delete(dis);
				super.getHibernateTemplate().save(distributed);
			}
		}else{
			super.getHibernateTemplate().save(distributed);
		}
		/*if(StrUtils.isNotNullOrBlank(dis.getId())){
			super.getHibernateTemplate().delete(dis);
			super.getHibernateTemplate().save(distributed);
		}else {
			super.getHibernateTemplate().save(distributed);
		}*/
	}

}
